﻿namespace ChessToys
{
    using System;
    using System.Collections.Generic;


    public class BoardEnumerator : IEnumerator<Position>
    {
        Board _board;
        int _x;
        int _y;

        public BoardEnumerator(Board board)
        {
            _board = board;
            Reset();
        }

        /// <inheritdoc />
        public Position Current
        {
            get { return new Position(_x, _y); }
        }

        /// <inheritdoc />
        public void Dispose()
        {
            _board = null;
        }

        /// <inheritdoc />
        object System.Collections.IEnumerator.Current
        {
            get { return Current; }
        }

        /// <inheritdoc />
        public bool MoveNext()
        {
            _x++;
            if (_x == _board.Size)
            {
                _x = 0;
                _y++;
            }
            return _y != _board.Size;
        }

        /// <inheritdoc />
        public void Reset()
        {
            _x = -1;
            _y = 0;
        }
    }
}
